<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>04.vue中的Js动画与Velocity</title>
    <link rel="stylesheet" href="animate.css">
    <script src="velocity.js"></script>
</head>
<style>
    .fade-enter, .fade-leave-to {
        opacity: 0;
    }
    .fade-enter-active, .fade-leave-active {
        transition: opacity 1s;
    }
</style>
<body>
    <div id="app">
        <transition 
            name="fade"
            @before-enter="handleBeforeEnter"
            @enter="handleEnter"
            @after-enter="handleAfterEnter"
        >
            <div v-show="show">hello world</div>
        </transition>

        <button @click="handleClick">切换</button>
    </div>
</body>
<script src="vue.js"></script>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            show: true
        },
        methods: {
            handleClick: function() {
                this.show = !this.show;
            },
            handleBeforeEnter: function(el) {
                el.style.color = 'red';
            },
            handleEnter: function(el, done) {
                setTimeout(() => {
                    el.style.color = 'green';
                }, 2000);// 2s后执行
                setTimeout(() => {
                    done() // 4s后执行done告诉vue动画结束，可以开始执行@after-enter
                }, 4000);
            },
            handleAfterEnter: function(el) {
                el.style.color = 'blue';
            }
        }
    })
</script>
</html>